package generic;

/**
 * 泛型类
 * @param <T>
 */
public class GenericA<T> {

    T key;

    public GenericA(T key) {
        this.key = key;
    }

    public T getKey() {
        return this.key;
    }

    //?是类型通配符
   public static void showKeyValue1(GenericA<?> genericA){
       System.out.println(genericA.getKey());
   }

    public static void main(String[] args) {
        //String
        GenericA<String> genericA = new GenericA<String>("aaaa");
        System.out.println(genericA.getKey());

        //Integer
        GenericA<Integer> genericA1 = new GenericA<Integer>(123);
        System.out.println(genericA1.getKey());


        //不指定具体类型
        GenericA  genericA2 = new GenericA(123);
        System.out.println(genericA2.getKey());

        //演示类型通配符
        GenericA<Integer> genericA3 = new GenericA<Integer>( 1);
        showKeyValue1(genericA3);

        GenericA<String> genericA4 = new GenericA<String>( "xxx");
        showKeyValue1(genericA4);

    }
}
